<?php include _include(ADMIN_PATH.'view/htm/header.inc.htm');?>

<div class="row">
    <div class="col-lg-10 offset-lg-1">

        <div class="btn-group m-b-1" role="group">
            <?php echo admin_tab_active(array(
					'set'=>array('url'=>url('plugin-setting-xn_search-set'), 'text'=>lang('admin_setting_search_set')),
					'cn_encode'=>array('url'=>url('plugin-setting-xn_search-cn_encode'), 'text'=>lang('admin_setting_search_cn_encode'))
				), $action);
			?>
        </div>

        <div class="card">
            <div class="card-block">
                <form action="<?php echo url("plugin-setting-xn_search");?>" method="post" id="form">
                    <div class="form-group row">
                        <label class="col-sm-2 form-control-label">搜索类型：</label>
                        <div class="col-sm-10">
                            <?php echo $input['type']; ?>
                        </div>
                    </div>
                    <div class="form-group row" id="site_url">
                        <label class="col-sm-2 form-control-label">第三方搜索 URL：</label>
                        <div class="col-sm-10">
                            <?php echo $input['site_url']; ?>
                            <p class="text-grey text-small">URL 中的 {keyword} 为关键字</p>
                        </div>
                    </div>

                    <div class="form-group row" id="range">
                        <div class="form-group row">
                            <label class="col-sm-2 form-control-label">开启搜索范围：</label>
                            <div class="col-sm-10">
                                <?php echo $input['range']; ?>
                            </div>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-2 form-control-label"></label>
                        <div class="col-sm-10">
                            <button type="submit" class="btn btn-primary btn-block" id="submit" data-loading-text="<?php echo lang('submiting');?>..."><?php echo lang('confirm');?></button>
                            <a role="button" class="btn btn-secondary btn-block m-t-1" href="javascript:history.back();">
                                <?php echo lang('back');?>
                            </a>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<?php include _include(ADMIN_PATH.'view/htm/footer.inc.htm');?>

<script>
    var jform = $("#form");
    var jsubmit = $("#submit");
    var referer = '<?php echo http_referer();?>';
    jform.on('submit', function() {
        jform.reset();
        jsubmit.button('loading');
        var postdata = jform.serialize();
        $.xpost(jform.attr('action'), postdata, function(code, message) {
            if (code == 0) {
                $.alert(message);
                jsubmit.text(message).delay(2000).button('reset').location(referer);
                return;
            } else {
                $.alert(message);
                jsubmit.button('reset');
            }
        });
        return false;
    });

    function search_type_radio_check(v) {
        var jfulltext = $('#fulltext');
        var jsphinx = $('#sphinx');
        var jsite_url = $('#site_url');
        var jrange = $('#range');
        if (v == 'fulltext') {
            jfulltext.show();
            jsite_url.hide();
            jrange.show();
        } else if (v == 'like') {
            jfulltext.hide();
            jsite_url.hide();
            jrange.show();
        } else if (v == 'sphinx') {
            jfulltext.hide();
            jsite_url.hide();
            jrange.hide();
        } else if (v == 'site_url') {
            jfulltext.hide();
            jsite_url.show();
            jrange.hide();
        }
    }
    jform.find('input[name="type"]').on('click', function() {
        var v = $(this).val();
        search_type_radio_check(v);
    });
    search_type_radio_check(jform.find('input[name="type"]').checked());
</script>